import axios from 'axios'
import { Message } from 'iview'

let api;

if (!(process.env.NODE_ENV === 'word'))
    api = 'http://192.168.3.237:5001'

axios.defaults.headers.common['Authorization'] = 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhcGkiLCJpc3MiOiJSdWlZaW5Db3JlIiwiaWQiOiIwMmI0YTFlMS04ZmI0LTQ4OGEtOGJjNS0zZTg2OGY5YWNjMDMiLCJuYW1lIjoi5a6i5oi3IiwiZW1haWwiOiI5NDQwODEwMTlAcXEuY29tIiwicGhvbmVfbnVtYmVyIjoiMTM4ODIxOTgzNzUiLCJuYmYiOjE1Mjc0NzYyODYsImV4cCI6MTUyODA4MTA4NiwiaWF0IjoxNTI3NDc2Mjg2fQ.ZTizbZ_swfQb-WkN4FKEI5GKGZYj_tTt5T5LVq_iZV4'

//配置公用axios
let iHttp = async(type, url, data) => {
    return new Promise((resolve, reject) => {
        data = data || {};
        let init = {
            method: type,
            url: url
        }
        type == 'get' ? init['params'] = data : init['data'] = data
        axios(init).then((response) => {
            if (response.data.code == 0 || 200)
                resolve(response.data)
        }, err => {
            Message.error(`${err.response.data.msg}`)
            reject(err)
        }).catch((err) => {
            console.log('错误', err)
            Message.error(`${err.response.data.msg}`)
            reject(err)
        })
    })
}


export default {
    api,
    iHttp
}